{% set Version = "openresty-1.13.6.2" %}
{% if salt['file.directory_exists']('/usr/local/nginx') %}
{% set NginxN = "Nginx1" %}
{% else %}
{% set NginxN = "nginx" %}
{% endif %}

include:
 - user.www

yum_package:
  pkg.installed:
    - names:
      - pcre-devel 
      - openssl-devel
      - gcc 
      - curl


nginx-source-install:
    file.managed:
        - name: /usr/local/src/{{Version}}.tar.gz
        - source: salt://nginx/files/{{Version}}.tar.gz
        - user: root
        - group: root
        - mode: 755
        - unless: test -f /usr/local/src/{{Version}}.tar.gz

    cmd.run:
        - name: cd /usr/local/src && tar zxf {{Version}}.tar.gz && cd  openresty-* && ./configure && make && make install && ln -s /usr/local/openresty/nginx  /usr/local/nginx && ln -s  /usr/local/nginx/sbin/nginx  /bin/
        - unless: test -d /usr/local/{{NginxN}}
        - require:
            - user: www-user-group
            - file: nginx-source-install

nginx-file-chmod:
    cmd.run:
        - name:  mkdir /www && chown  www:www /www
        - unless: test -d /www
